package com.cz.cloud.consume;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.cz.cloud.dto.User;

@RestController
@RequestMapping("user")
public class UserConsume {
	
	
	@LoadBalanced
	@Bean
	RestTemplate restTemplate() {
		return new RestTemplate();
	}

	@Autowired
	RestTemplate restTemplate;

	@RequestMapping("/userList")
	public String userConsume(User user) {
		Map<String,Object> para = new HashMap<>();
		para.put("userName", user.getUserName());
        para.put("age", user.getAge());
        String info = "";
		String info1 = this.restTemplate.getForObject("http://service1/user/userList?userName=cz&age=12",String.class);
		String info2 = this.restTemplate.getForObject("http://service1/user/userList?userName={userName}&age={age}", String.class,para);
		String info3= this.restTemplate.postForObject("http://service1/user/puserList?userName={userName}&age={age}", null,String.class,para);
		String info4= this.restTemplate.postForObject("http://service1/user/puserList", user,String.class);
        info = info + info1 + "</br>";
        info = info + info2 + "</br>";
        info = info + info3 +"</br>";
        info = info + info4 +"</br>";
		return info;
	}
}
